package com.mall.web.controller.content.admin;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.mall.content.articleCategory.domain.dto.ArticleCategoryDto;
import com.mall.content.articleCategory.domain.vo.ArticleCategoryVo;
import com.mall.content.articleCategory.service.IArticleCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.common.core.page.TableDataInfo;

/**
 * 文章分类Controller
 * 
 * @author mall
 * @date 2024-05-17
 */
@RestController
@RequestMapping("/admin/content/articleCategory")
public class ArticleCategoryController extends BaseController
{
    @Autowired
    private IArticleCategoryService articleCategoryService;

    /**
     * 查询文章分类列表
     */
    @PreAuthorize("@ss.hasPermi('content:articleCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArticleCategoryDto articleCategory)
    {
        startPage();
        List<ArticleCategoryVo> list = articleCategoryService.selectArticleCategoryList(articleCategory);
        return getDataTable(list);
    }

    /**
     * 导出文章分类列表
     */
    @PreAuthorize("@ss.hasPermi('content:articleCategory:export')")
    @Log(title = "文章分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArticleCategoryDto articleCategoryDto)
    {
        List<ArticleCategoryVo> list = articleCategoryService.selectArticleCategoryList(articleCategoryDto);
        ExcelUtil<ArticleCategoryVo> util = new ExcelUtil<ArticleCategoryVo>(ArticleCategoryVo.class);
        util.exportExcel(response, list, "文章分类数据");
    }

    /**
     * 获取文章分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('content:articleCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(articleCategoryService.selectArticleCategoryById(id));
    }

    /**
     * 新增文章分类
     */
    @PreAuthorize("@ss.hasPermi('content:articleCategory:add')")
    @Log(title = "文章分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArticleCategoryDto articleCategoryDto)
    {
        return toAjax(articleCategoryService.insertArticleCategory(articleCategoryDto));
    }

    /**
     * 修改文章分类
     */
    @PreAuthorize("@ss.hasPermi('content:articleCategory:edit')")
    @Log(title = "文章分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArticleCategoryDto articleCategoryDto)
    {
        return toAjax(articleCategoryService.updateArticleCategory(articleCategoryDto));
    }

    /**
     * 删除文章分类
     */
    @PreAuthorize("@ss.hasPermi('content:articleCategory:remove')")
    @Log(title = "文章分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(articleCategoryService.deleteArticleCategoryByIds(ids));
    }
}
